package com.erp.gather.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.erp.gather.domain.bo.ErpSellerStoreProductExpandBo;
import com.erp.gather.domain.vo.ErpSellerStoreProductExpandVo;
import com.erp.gather.service.IErpSellerStoreProductExpandService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.gather.api.domain.ErpSellerStoreProductExpand;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
 *
 * @author erp
 * @date 2023-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreProductExpand")
public class ErpSellerStoreProductExpandController extends BaseController {

    private final IErpSellerStoreProductExpandService iErpSellerStoreProductExpandService;

    /**
     * 查询卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreProductExpandVo> list(ErpSellerStoreProductExpandBo bo, PageQuery pageQuery) {
        return iErpSellerStoreProductExpandService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSellerStoreProductExpandVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerStoreProductExpandService.queryById(id));
    }

    /**
     * 新增卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @Log(title = "卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreProductExpandBo bo) {
        return toAjax(iErpSellerStoreProductExpandService.insertByBo(bo));
    }

    /**
     * 修改卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @Log(title = "卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreProductExpandBo bo) {
        return toAjax(iErpSellerStoreProductExpandService.updateByBo(bo));
    }

    /**
     * 删除卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     *
     * @param ids 主键串
     */
    @Log(title = "卖家在线商品拓展;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreProductExpandService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    @PostMapping("/selectSellerStoreProductExpandByLaw")
    public R<Object> selectSellerStoreProductExpandByLaw(@RequestBody LambdaQueryWrapper law) {
        return iErpSellerStoreProductExpandService.selectSellerStoreProductExpandByLaw(law);
    }

    @PostMapping("/updateErpSellerStoreProductExpand")
    public R<Object> updateErpSellerStoreProductExpand(@RequestBody ErpSellerStoreProductExpand erpSellerStoreProductExpand) {
        return iErpSellerStoreProductExpandService.updateErpSellerStoreProductExpand(erpSellerStoreProductExpand);
    }

    @PostMapping("/getErpSellerStoreProductExpandInfo")
    public R<Object> getErpSellerStoreProductExpandInfo(@RequestBody ErpSellerStoreProductExpand erpSellerStoreProductExpand) {
        return iErpSellerStoreProductExpandService.getErpSellerStoreProductExpandInfo(erpSellerStoreProductExpand);
    }

    @PostMapping("/deleteErpSellerStoreProductExpand")
    public R<Object> deleteErpSellerStoreProductExpand(@RequestBody ErpSellerStoreProductExpand erpSellerStoreProductExpand) {
        return iErpSellerStoreProductExpandService.deleteErpSellerStoreProductExpand(erpSellerStoreProductExpand);
    }

    @PostMapping("/updateModuleCount")
    public void updateModuleCount(@RequestBody List<Long> list) {
        iErpSellerStoreProductExpandService.updateModuleCount(list);
    }

}
